package com.example.ai;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class MCPSubscriber implements MessageListener {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Override
    public void onMessage(Message message, byte[] pattern) {
        String question = message.toString();
        String answer = "AI 的回答是：[" + question + "] 的答案";
        redisTemplate.convertAndSend("answerQueue", answer);
    }
}